/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						       memory_window.h

	$Header: /game/memory_window.h $

	$NoKeywords: $

 ************************************************************************/
// kill the 255+ character identifier warning.  Templates tend to exceed that easily.
#include "precompiled.h"
#pragma warning( disable: 4786 )

#include "memory_window.h"

#include "format_string.h"
#include "idle_processor.h"
#include "options.h"
#include "standard_fonts.h"
#include "text_window.h"

namespace
{
	// ------------------------------------------------------------
	// window which constantly displays how much memory is in use
	// ------------------------------------------------------------
	class t_memory_window : public t_text_window, public t_idle_processor
	{
	public:
		t_memory_window();

		virtual void on_idle();
	protected:
		unsigned long m_memory;
	};
	
	t_counted_ptr<t_memory_window> g_memory_window;
};

// ------------------------------------------------------------
// window which constantly displays how much memory is in use
// ------------------------------------------------------------
t_memory_window::t_memory_window() 
			   : t_text_window( ::get_font( 30 ), t_screen_rect(0,0,100,30), 0, "0 MB",
			                    t_pixel_24(255,255,255) ),
			     t_idle_processor( 0, 1000 )
{
	m_memory = 0;
}

								 
// ------------------------------------------------------------
// window which constantly displays how much memory is in use
// ------------------------------------------------------------
void t_memory_window::on_idle()
{
/*	unsigned long memory;

	memory = get_allocated_memory() / 1048576;

	if (memory == m_memory)
		return;
	m_memory = memory;
	set_text( format_string( "%i Mb", m_memory ) );
*/
}

// ------------------------------------------------------------
// ------------------------------------------------------------
void close_memory_window()
{
	if (g_memory_window == 0)
		return;
	g_memory_window->close();
	g_memory_window = 0;
}

// ------------------------------------------------------------
// ------------------------------------------------------------
void move_memory_window_to_front()
{
	if (g_memory_window == 0)
		return;
	g_memory_window->move_to_front();
}

// ------------------------------------------------------------
// ------------------------------------------------------------
void show_memory_window()
{
	if (g_memory_window != 0 && g_memory_window->is_open())
	{
		move_memory_window_to_front();
		return;
	}
	if (!show_cheat_menus())
		return;
	g_memory_window = new t_memory_window;
}

bool memory_window_is_open()
{
	return g_memory_window != 0 && g_memory_window->is_open();
}
